﻿
<template>
    <section>




        <!--工具条-->
        <el-col :span='24' class='toolbar' style='padding-bottom: 0px;'>
            <el-form :inline='true' :model='filters' @submit.native.prevent>
                <el-form-item>
                    <el-input v-model='filters.name' placeholder='地址/SIM'></el-input>
                </el-form-item>

                <el-form-item>
                    <el-input v-model='filters.yb' placeholder='从站地址'></el-input>
                </el-form-item>


                <el-form-item>
                    <el-button type='primary' @click='getDtoPage'>查询</el-button>
                </el-form-item>

            </el-form>
        </el-col>



        <!--列表-->
        <el-table :data='users' highlight-current-row v-loading='listLoading' @selection-change='selsChange'
                  style='width: 100%;'
                  sortable='custom' @sort-change='sortKey'>

            <el-table-column prop='CJQ_Id' label='编号' width=''>  </el-table-column>
            <el-table-column prop='CJQ_Addr' label='地址' width=''>  </el-table-column>
            <el-table-column prop='CJQ_SIM' label='SIM' width=''>  </el-table-column>
            <el-table-column prop='CJQ_Yb' label='从站地址' width=''>  </el-table-column>
            <el-table-column prop='CJQ_GPS' label='GPS' width=''>  </el-table-column>
            <el-table-column prop='CJQ_Ver' label='类型' width=''>  </el-table-column>
            <el-table-column prop='CJQ_Count' label='数量' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ1' label='寄存器1' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ2' label='寄存器2' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ3' label='寄存器3' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ4' label='寄存器4' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ5' label='寄存器5' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ6' label='寄存器6' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ7' label='寄存器7' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ8' label='寄存器8' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ9' label='寄存器9' width=''>  </el-table-column>
            <el-table-column prop='CJQ_JCQ10' label='寄存器10' width=''>  </el-table-column>
            <el-table-column prop='UpdateTIme' label='更新时间' width='' :formatter="dateFormat">  </el-table-column>


            <el-table-column prop='State' label='状态' width=''>  </el-table-column>

            <el-table-column label='操作' width='150'>
                <template scope='scope'> 
                    <el-button type='danger' size='small' @click='handleDel(scope.$index, scope.row)'> 删除 </el-button>
                </template>
            </el-table-column>


        </el-table>



        <!-- 工具条 ,分页 -->
        <el-col :span='24' class='toolbar'>
            <el-pagination @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="pageIndex"
                           :page-sizes="[ 20, 50, 100]"
                           :page-size="pageSize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="total"
                           style='float:right;'>
            </el-pagination>
        </el-col>



        <!--编辑界面-->
        <el-dialog title='编辑' :visible.sync='editFormVisible' v-model='editFormVisible' :close-on-click-modal='false'>
            <el-form :model='editForm' label-width='80px' :rules='editFormRules' ref='editForm'>

                <el-form-item label='' prop='CJQ_Id'>
                    <el-input v-model='editForm.CJQ_Id' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Addr'>
                    <el-input v-model='editForm.CJQ_Addr' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_SIM'>
                    <el-input v-model='editForm.CJQ_SIM' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Yb'>
                    <el-input v-model='editForm.CJQ_Yb' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_GPS'>
                    <el-input v-model='editForm.CJQ_GPS' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Ver'>
                    <el-input v-model='editForm.CJQ_Ver' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Count'>
                    <el-input v-model='editForm.CJQ_Count' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ1'>
                    <el-input v-model='editForm.CJQ_JCQ1' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ2'>
                    <el-input v-model='editForm.CJQ_JCQ2' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ3'>
                    <el-input v-model='editForm.CJQ_JCQ3' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ4'>
                    <el-input v-model='editForm.CJQ_JCQ4' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ5'>
                    <el-input v-model='editForm.CJQ_JCQ5' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ6'>
                    <el-input v-model='editForm.CJQ_JCQ6' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ7'>
                    <el-input v-model='editForm.CJQ_JCQ7' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ8'>
                    <el-input v-model='editForm.CJQ_JCQ8' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ9'>
                    <el-input v-model='editForm.CJQ_JCQ9' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ10'>
                    <el-input v-model='editForm.CJQ_JCQ10' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='UpdateTIme'>
                    <el-input v-model='editForm.UpdateTIme' auto-complete='off'></el-input>
                </el-form-item>


            </el-form>
            <div slot='footer' class='dialog-footer'>
                <el-button @click.native='editFormVisible = false'>取消</el-button>
                <el-button type='primary' @click.native='editSubmit' :loading='editLoading'>提交</el-button>
            </div>
        </el-dialog>



        <!--新增界面-->
        <el-dialog title='新增' :visible.sync='addFormVisible' v-model='addFormVisible' :close-on-click-modal='false'>
            <el-form :model='addForm' label-width='80px' :rules='addFormRules' ref='addForm'>



                <el-form-item label='' prop='CJQ_Id'>
                    <el-input v-model='addForm.CJQ_Id' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Addr'>
                    <el-input v-model='addForm.CJQ_Addr' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_SIM'>
                    <el-input v-model='addForm.CJQ_SIM' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Yb'>
                    <el-input v-model='addForm.CJQ_Yb' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_GPS'>
                    <el-input v-model='addForm.CJQ_GPS' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Ver'>
                    <el-input v-model='addForm.CJQ_Ver' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_Count'>
                    <el-input v-model='addForm.CJQ_Count' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ1'>
                    <el-input v-model='addForm.CJQ_JCQ1' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ2'>
                    <el-input v-model='addForm.CJQ_JCQ2' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ3'>
                    <el-input v-model='addForm.CJQ_JCQ3' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ4'>
                    <el-input v-model='addForm.CJQ_JCQ4' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ5'>
                    <el-input v-model='addForm.CJQ_JCQ5' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ6'>
                    <el-input v-model='addForm.CJQ_JCQ6' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ7'>
                    <el-input v-model='addForm.CJQ_JCQ7' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ8'>
                    <el-input v-model='addForm.CJQ_JCQ8' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ9'>
                    <el-input v-model='addForm.CJQ_JCQ9' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='CJQ_JCQ10'>
                    <el-input v-model='addForm.CJQ_JCQ10' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='' prop='UpdateTIme'>
                    <el-input v-model='addForm.UpdateTIme' auto-complete='off'></el-input>
                </el-form-item>



            </el-form>
            <div slot='footer' class='dialog-footer'>
                <el-button @click.native='addFormVisible = false'>取消</el-button>
                <el-button type='primary' @click.native='addSubmit' :loading='addLoading'>提交</el-button>
            </div>
        </el-dialog>





    </section>
</template>

<script>

    import util from '../../../util/date'
    import { testapi, getPage_MQXT_CaiJiQiModel, getByID_MQXT_CaiJiQiModel, edit_MQXT_CaiJiQiModel, add_MQXT_CaiJiQiModel, batchRemove_MQXT_CaiJiQiModel, Remove_MQXT_CaiJiQiModel } from '../../api/api';

    export default {
        data() {   // 全局变量
            return {
                filters: { name: '', yb:'' },
                users: [],
                //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                total: 0,
                pageSize: 20,
                pageIndex: 1,
                sidx: null,   //  排序字段
                order: null,  //  排序方式， 正序\倒序
                //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                listLoading: false,
                sels: [],//列表选中列
                addDialogFormVisible: false,
                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    CJQ_Id: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Addr: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_SIM: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Yb: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_GPS: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Ver: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Count: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ1: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ2: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ3: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ4: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ5: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ6: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ7: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ8: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ9: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ10: [{ required: true, message: '请输入', trigger: 'blur' }],
                    UpdateTIme: [{ required: true, message: '请输入', trigger: 'blur' }],
                }
                ,
                //编辑界面数据
                editForm: {
                    CJQ_Id: 0,
                    CJQ_Addr: '',
                    CJQ_SIM: '',
                    CJQ_Yb: '',
                    CJQ_GPS: '',
                    CJQ_Ver: '',
                    CJQ_Count: 0,
                    CJQ_JCQ1: '',
                    CJQ_JCQ2: '',
                    CJQ_JCQ3: '',
                    CJQ_JCQ4: '',
                    CJQ_JCQ5: '',
                    CJQ_JCQ6: '',
                    CJQ_JCQ7: '',
                    CJQ_JCQ8: '',
                    CJQ_JCQ9: '',
                    CJQ_JCQ10: '',
                    UpdateTIme: 0,
                }
                ,
                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    CJQ_Id: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Addr: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_SIM: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Yb: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_GPS: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Ver: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_Count: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ1: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ2: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ3: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ4: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ5: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ6: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ7: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ8: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ9: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CJQ_JCQ10: [{ required: true, message: '请输入', trigger: 'blur' }],
                    UpdateTIme: [{ required: true, message: '请输入', trigger: 'blur' }],
                }
                ,
                //新增界面数据
                addForm: {
                    CJQ_Addr: '',
                    CJQ_SIM: '',
                    CJQ_Yb: '',
                    CJQ_GPS: '',
                    CJQ_Ver: '',
                    CJQ_Count: 0,
                    CJQ_JCQ1: '',
                    CJQ_JCQ2: '',
                    CJQ_JCQ3: '',
                    CJQ_JCQ4: '',
                    CJQ_JCQ5: '',
                    CJQ_JCQ6: '',
                    CJQ_JCQ7: '',
                    CJQ_JCQ8: '',
                    CJQ_JCQ9: '',
                    CJQ_JCQ10: '',
                    UpdateTIme: 0,
                }

            }
        },
        methods: {    // 全局方法

            //时间格式化
            dateFormat: function (row, column) {

                var t = new Date(row.UpdateTIme);//row 表示一行数据, updateTime 表示要格式化的字段名称
                return t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds() + "." + t.getMilliseconds();
            },

            //性别显示转换
            //formatSex: function (row, column) {
            //    return row.C_Value == 2 ? '男' : row.C_Value;
            //},
            //formatterCreateTime: function (row, column) {
            //    return (!row.C_CreateTime || row.C_CreateTime == '') ? '' : util.formatDate.format(new Date(row.C_CreateTime), 'yyyy-MM-dd');
            //},
            handleCurrentChange(val) {
                this.pageIndex = val;
                this.getDtoPage();
            },
            // 测试
            sortKey(val) {
                console.log(val)
            },
            // 每页数
            handleSizeChange(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDtoPage();
            },

            //获取用户列表
            getDtoPage() {
                let para = {
                    page: this.pageIndex,
                    pageSize: this.pageSize,
                    key: this.filters.name,
                    yb: this.filters.yb,
                    sidx: this.sidx,
                    order: this.order
                };
                this.listLoading = true;

                getPage_MQXT_CaiJiQiModel(para).then((res) => {
                    console.log(res);
                    this.total = res.data.response.dataCount;
                    this.users = res.data.response.data;
                    this.listLoading = false;

                });
            },
            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = { id: row.CJQ_Id };
                    Remove_MQXT_CaiJiQiModel(para).then((res) => {
                        if (util.isEmt.format(res)) {
                            this.listLoading = false;
                            return;
                        }
                        this.listLoading = false;
                        if (res.data.success) {
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                        } else {
                            this.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                        this.getDtoPage();
                    });
                }).catch((c) => {
                    console.log(c);
                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;

                let para_getGetByID = { id: row.CJQ_Id };

                getByID_MQXT_CaiJiQiModel(para_getGetByID).then((getDto) => {

                    this.editForm = Object.assign({}, getDto.data.response);
                });
            },
            //显示新增界面
            handleAdd() {
                this.addFormVisible = true;
                this.addForm = {
                    CJQ_Addr: '',
                    CJQ_SIM: '',
                    CJQ_Yb: '',
                    CJQ_GPS: '',
                    CJQ_Ver: '',
                    CJQ_Count: 0,
                    CJQ_JCQ1: '',
                    CJQ_JCQ2: '',
                    CJQ_JCQ3: '',
                    CJQ_JCQ4: '',
                    CJQ_JCQ5: '',
                    CJQ_JCQ6: '',
                    CJQ_JCQ7: '',
                    CJQ_JCQ8: '',
                    CJQ_JCQ9: '',
                    CJQ_JCQ10: '',
                    UpdateTIme: 0,
                }
                    ;
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                        }).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.editForm);
                            console.log(para);
                            edit_MQXT_CaiJiQiModel(para).then((res) => {

                                if (util.isEmt.format(res)) {
                                    this.editLoading = false;
                                    return;
                                }
                                if (res.data.success) {
                                    this.editLoading = false;

                                    this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                    });
                                    this.$refs['editForm'].resetFields();
                                    this.editFormVisible = false;
                                    this.getDtoPage();
                                } else {
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'error'
                                    });
                                }
                            });
                        });
                    }
                });
            },
            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                        }).then(() => {
                            this.addLoading = true;
                            let para = Object.assign({}, this.addForm);

                            add_MQXT_CaiJiQiModel(para).then((res) => {

                                if (util.isEmt.format(res)) {
                                    this.addLoading = false;
                                    return;
                                }

                                if (res.data.success) {
                                    this.addLoading = false;
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                    });
                                    this.$refs['addForm'].resetFields();
                                    this.addFormVisible = false;
                                    this.getDtoPage();
                                }
                                else {
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'error'
                                    });
                                }
                            });
                        });
                    }
                });
            },
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {

                var ids = this.sels.map(item => item.CJQ_Id).toString();
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning',
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then(() => {
                    this.listLoading = true;
                    let para = { ids: ids };

                    batchRemove_MQXT_CaiJiQiModel(para).then((res) => {
                        this.listLoading = false;

                        if (res.data.success) {
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                        } else {
                            this.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                        this.getDtoPage();
                        console.log(res)
                    });
                }).catch(() => {

                });
            }
        },
        mounted() {
            this.getDtoPage();
        }
    }

</script>

<style scoped>
</style>
